<h3 class="block-title">操作:
    <a target="_self" href="/art/article/create" class="btn btn-xs btn-primary">新增</a>
    <button type="button" class="btn btn-xs btn-success action" value="{{ \App\Models\Article::STATE_PUBLISHED }}">发布</button>
    <button type="button" class="btn btn-xs btn-dark action" value="{{ \App\Models\Article::STATE_CANCELED }}">撤回</button>
    <button type="button" class="btn btn-xs btn-danger action" value="{{ \App\Models\Article::STATE_DELETED }}">删除</button>
    <button type="button" class="btn btn-xs btn-info" id="table-sort">排序</button>
    <button type="button" class="btn btn-xs btn-primary" id="export-excel">导出Excel</button>
</h3>
<div class="block-options">
    <div class="btn-group btn-group-xs">
        <input type="hidden" name="state" id="state" value=""/>
        <button type="button" class="btn btn-info filter" value="">全部</button>
        <button type="button" class="btn btn-default filter" value="{{ \App\Models\Article::STATE_UNPUBLISHED }}">未发布</button>
        <button type="button" class="btn btn-default filter" value="{{ \App\Models\Article::STATE_CANCELED }}">已撤回</button>
        <button type="button" class="btn btn-default filter" value="{{ \App\Models\Article::STATE_PUBLISHED }}">已发布</button>
    </div>
    <button type="button" class="btn-block-option" data-toggle="block-option" data-action="fullscreen_toggle"><i class="si si-size-fullscreen"></i></button>
</div>

<script>
    /* 操作 */
    $('.action').click(function () {
        var state = $(this).val();
        var rows = $('#table').bootstrapTable('getSelections');

        var ids = getIds();
        if (ids.length === 0) {
            return msg('请至少选择一项', 'warning');
        }
        if(confirm("确定要执行该操作吗？")) {
            $.ajax({
                url: '/art/article/state/' + state,
                type: 'POST',
                data: {'_token': '{{ csrf_token() }}', 'ids': ids},
                success: function (res) {
                    if(res.code === 200) {
                        $('#table').bootstrapTable('refresh');
                        return msg(res.message, 'success');
                    } else {
                        return msg(res.message, 'error');
                    }
                }
            });
        }
    });

    /**
     * 导出excel
     */
    $('#export-excel').click(function () {
        var queryStr = $('#form-query input,#form-query select,#state').serialize();
        location.href = '/art/article/export/excel?'+ queryStr;
    })
</script>
